#pragma once
#include "stdafx.h"
class FrameBufferDesc
	: public BaseDesc
{
public:
	FrameBufferDesc()
	{
		Width=Height=TEXTURE_RESOLUTION;
		bDepthEnabled=true;
		bStencilEnabled=false;
		nColorAttachments=1;
	};
	unsigned int Width, Height, nColorAttachments;
	bool bDepthEnabled, bStencilEnabled;
};
class FrameBuffer :
	public Base
{
public:
	FrameBuffer(FrameBufferDesc&);
	~FrameBuffer(void);
	void Bind();
	void Unbind();
	void BindTexture(string);
	void AttachToColor(sptr<GameResource>, unsigned int nColor=0, unsigned int nFace=0);
	void AttachToDepth(sptr<GameResource>);
	void AttachToStencil(sptr<GameResource>);
	void UnbindTexture();
	void EnableColors(unsigned int nColor=1);
	void DisableColors();
	void DetachDepth();
	void Reset();
	sptr<GameResource> GetDepth();
	sptr<GameResource> GetColor(unsigned int attachmentID=0);
	sptr<GameResource> GetStencil();
	Vec2 GetDimensions();
private:
	BBVector<sptr<GameResource>> Attachments;
	unsigned int Width, Height, nColorAttachments;
	GLuint FBOID, RBOID;
	void Init();
	bool bDepthEnabled, bStencilEnabled;
	void AttachDepth();
	void AttachColor(unsigned int);
	void AttachStencil();
	void AddTexture(TextureDesc&, GLenum);
	sptr<GameResource> GetAttachment(string);
	bool TestFBO();
};

